dotConnect for SQLite Documentation
Devart.Data.SQLite Namespace / SQLiteAggregateFunction<T1,T2,TResult> Class
Type of the first user-defined function parameter.
Type of the second user-defined function parameter.
Type of the user-defined function result.
Members Example

SQLiteAggregateFunction<T1,T2,TResult> Class
Generic base class for user-defined aggregate functions with two parameters.
Syntax
'Declaration
 
Public MustInherit Class SQLiteAggregateFunction
    (Of T1,T2,TResult) 
   Inherits SQLiteAggregateFunction
   Implements System.IDisposable 
 
Type Parameters
T1
Type of the first user-defined function parameter.
T2
Type of the second user-defined function parameter.
TResult
Type of the user-defined function result.
Remarks

Use this class to derive user-defined aggregate functions with two parameters from it. This generic class was introduced to ease the user-defined function creating. It allows to specify parameter count, type, and function result type. As an alternative, you may use SQLiteAggregateFunction to create user-defined aggregate functions with any number of parameters.

The result of an aggregate function is a scalar object, but its value is accumulated when processing query result records. It is executed for each record, and its result can be accumulated. Average, Summ, or Count are the examples of such functions.

To register the user-defined aggregate funtion, create the class, derived from SQLiteAggregateFunction and pass its name and number of arguments to the base class constructor.

You should also override Step and Complete methods. Step method should implement the way of acumulating and storing result, and Complete method should process the accumulated value after all records were processed.

Example
This example illustrates creating and using user-defined function for calculating Average value. Step method is used to accumulate sum of values and iteration count, and Complete method is used to divide sum by iteration count.
public class MyFunction : SQLiteAggregateFunction<long, double> {

        private long count;

        public MyFunction() : base("Average") {

                count = 0;
        }

        public override void Step(long arg1, SQLiteConnection connection, ref double contextData) {

                contextData = contextData + arg1;
                count++;
        }

        public override double Complete(SQLiteConnection connection, double contextData) {

                return contextData / count;
        }
}
Inheritance Hierarchy

System.Object
   Devart.Data.SQLite.SQLiteFunction
      Devart.Data.SQLite.SQLiteAggregateFunction
         Devart.Data.SQLite.SQLiteAggregateFunction<T1,T2,TResult>

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also